package com.stars.empoly.vmodel

import android.app.Activity
import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.hwangjr.rxbus.RxBus
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.util.SmartGlideImageLoader
import com.stars.empoly.activity.AddressActivity
import com.stars.empoly.config.ConfigRx
import com.stars.empoly.config.MIntentAction
import com.stars.empoly.model.ServiceList
import com.stars.empoly.utils.net.NetEngine
import com.trailer.base.base.BRRepository
import com.trailer.base.base.BRViewModel
import com.trailer.base.net.IResp
import kotlinx.coroutines.launch

/**
 *
 *on 2020/9/25
 */
class HeartVModel(application: Application) : BRViewModel<BRRepository>(application) {


    var index= MutableLiveData<Int>()

    var bean=MutableLiveData<ServiceList>()

    fun toTechnician(id:String?){
        viewModelScope.launch {
            var it= NetEngine.service.platformServiceList(id,null,null)
            if(it.ok()){
                bean.value=it.data

            }

        }

    }

    fun toFollow( id:String?,position:Int?){

        viewModelScope.launch{
            var it=repository().lreq { NetEngine.service.follow(id) }
            if(it.ok(true)){
                index.value=position
                //刷新首页
                RxBus.get().post(ConfigRx.CANCEL_HEART_REFRESH, "")

            }
        }

    }



    override fun apiFunc(): suspend () -> IResp<*> {
        return { NetEngine.service.memberFollowList(10,repository().page) }

    }






}
